<template>
  <div class="app-container">
    <div class="filter-container">{{shopInfo.shopName}}</div>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane name="edit" v-if="btnPower.ShopEdit">
        <span slot="label"><i class="el-icon-date"></i> 店铺信息</span>
        <el-form :model="editForm" :rules="editRules" ref="editForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="状态">
              <el-radio-group v-model="editForm.status">
                  <el-radio :label="10">开通</el-radio>
                  <el-radio :label="20">停用</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="商户类型" prop="sources">
            <el-select v-model="editForm.sources" multiple placeholder="请选择商户类型" style="width: 100%;">
              <el-option label="京东自助" value="10"></el-option>
              <el-option label="微信赠机" value="20"></el-option>
              <el-option label="小屏自助" value="30"></el-option>
              <el-option label="扫枪" value="40"></el-option>
              <el-option label="到家小程序" value="50"></el-option>
              <el-option label="双屏自助" value="60"></el-option>
              <el-option label="彩娱自助" value="70"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="对接模式" v-if="disabled">
              <el-radio-group v-model="editForm.dockType">
                  <el-radio :label="10">大中台</el-radio>
                  <el-radio :label="20">小中台</el-radio>
                  <el-radio :label="30">不需要对接</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="ERP系统" prop="erpSysId">
              <el-select v-model="editForm.erpSysId" filterable placeholder="请选择ERP系统">
                  <el-option
                          v-for="(item,index) in erps"
                          :label="item.name"
                          :value="item.id"
                          :key="index">
                  </el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="店铺名称" prop="name">
              <el-input v-model="editForm.name"></el-input>
          </el-form-item>
          <el-form-item label="小票名称">
              <el-input type="textarea" :rows="3" placeholder="请输入按钮说明" v-model="editForm.ticketName"></el-input>
          </el-form-item>
          <!-- <el-form-item label="商户编号" prop="shopNo">
              <el-input v-model="editForm.shopNo" :disabled="true"></el-input>
          </el-form-item> -->
          <el-form-item label="商户登录账号" prop="linkmanPhone">
              <el-input v-model="editForm.linkmanPhone"></el-input>
          </el-form-item>
          <el-form-item label="商户登录密码" prop="pwd" >
              <el-button class="filter-item" type="primary" size="small" icon="el-icon-edit-outline" @click="getLoginResetPwd">重置密码</el-button>
          </el-form-item>
          <el-form-item label="开启前端服务" prop="inspect" v-if="disabled">
              <el-radio-group v-model="editForm.inspect">
                  <el-radio :label="10">开启</el-radio>
                  <el-radio :label="20">不开启</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="心跳间隔(分)" prop="heartInterval" v-if="isHid()&&disabled">
              <el-input-number v-model="editForm.heartInterval" :min="1" :max="120" :precision="0" ></el-input-number>
          </el-form-item>
          <el-form-item label="四舍五入类型" v-if="disabled">
              <el-radio-group v-model="editForm.amtRoundRule">
                  <el-radio :label="10">无</el-radio>
                  <el-radio :label="20">商品</el-radio>
                  <el-radio :label="30">订单</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="一码多品" v-if="disabled">
              <el-radio-group v-model="editForm.severalSell">
                  <el-radio :label="10">可售</el-radio>
                  <el-radio :label="20">非售</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="商品积分保留小数位数" prop="productIntegral" v-if="disabled">
              <el-input-number v-model="editForm.productIntegral" :min="0" :max="3" :step="1" :precision="0" ></el-input-number>
          </el-form-item>
          <el-form-item label="订单积分保留小数位数" prop="orderIntegral" v-if="disabled">
              <el-input-number v-model="editForm.orderIntegral" :min="0" :max="3" :step="1" :precision="0"></el-input-number>
          </el-form-item>
          <el-form-item label="会员级别" v-if="disabled">
              <el-radio-group v-model="editForm.level">
                  <el-radio :label="10">店铺级别</el-radio>
                  <el-radio :label="20">商超级别</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="赠品" v-if="disabled">
              <el-radio-group v-model="editForm.ifMergeGift">
                  <el-radio :label="10">合并</el-radio>
                  <el-radio :label="20">不合并</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="散装特价" v-if="disabled">
              <el-radio-group v-model="editForm.bulkRebate">
                  <el-radio :label="10">以折扣价为基数计算</el-radio>
                  <el-radio :label="30">以售价为基数计算</el-radio>
                  <el-radio :label="20">否</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="商品折扣基数" v-if="disabled">
              <el-radio-group v-model="editForm.disRadix">
                  <el-radio :label="10">折扣价</el-radio>
                  <el-radio :label="20">售价</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="价格为0" v-if="disabled">
              <el-radio-group v-model="editForm.stdPriceZoSell">
                  <el-radio :label="10">可售</el-radio>
                  <el-radio :label="20">非售</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="扫商品算折扣" v-if="disabled">
              <el-radio-group v-model="editForm.reckonDiscount">
                  <el-radio :label="10">是</el-radio>
                  <el-radio :label="20">否</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="小中台回写" v-if="disabled">
              <el-radio-group v-model="editForm.smallWrite">
                  <el-radio :label="10">已同步</el-radio>
                  <el-radio :label="20">未同步</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="会员远程地址" prop="memberRemtUrl" v-if="disabled">
              <el-input v-model="editForm.memberRemtUrl"></el-input>
          </el-form-item>
          <el-form-item>
              <el-button type="primary" @click="editSubmitForm('editForm')">保存</el-button>
              <el-button @click="resetForm('editForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>

      <el-tab-pane name="device" label="设备" v-if="btnPower.ShopDevice">
        <div class="filter-container">
          <el-button v-if="btnPower.ShopDeviceAdd" class="filter-item" type="primary" icon="el-icon-document" @click="getDevicePoput()">添加</el-button>
        </div>
        <el-table
          :data="deviceLists"
          v-loading="deviceListLoading"
          element-loading-text="请稍后"
          border
          fit
          highlight-current-row>
          <el-table-column
                  prop="id"
                  label="设备id"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="deviceNo"
                  label="机器编号"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="name"
                  label="设备名称"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="salt"
                  label="加密密钥"
                  width="90"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="status"
                  :formatter="deviceStatus"
                  label="状态"
                  width="60"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="whetherTest"
                  :formatter="deviceWhetherTest"
                  label="是否测试"
                  width="80"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="createAt"
                  :formatter="timeFormat"
                  label="创建时间"
                  align="center"
                  width="160">
          </el-table-column>
          <el-table-column
                  fixed="right"
                  label="操作"
                  width="150"
                  align="center">
              <template slot-scope="scope">
                  <el-button v-if="btnPower.ShopDeviceRev" type="primary" size="small" @click="getDevicePoput(scope.row)">编辑</el-button>
                  <el-button v-if="scope.row.type!=20&&btnPower.ShopDeviceDel" type="danger" size="small" @click="getDelDevice(scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>
        <pagination v-show="deviceTotal>0" :total="deviceTotal" :page.sync="deviceParams.current" :limit.sync="deviceParams.size" @pagination="getDeviceList" />
        <el-dialog
          :title="devicePopupType==1?'添加设备':'修改设备'"
          :visible.sync="devicePopup"
          :close-on-click-modal=false
          :destroy-on-close=true
          width="500px"
          center>
          <el-form :model="deviceForm" ref="deviceForm" :rules="deviceRules" label-width="100px" class="demo-ruleForm">
            <el-form-item label="设备名称" prop="name">
                <el-input v-model="deviceForm.name"></el-input>
            </el-form-item>
            <el-form-item label="设备编号" prop="deviceNo">
                <el-input v-model="deviceForm.deviceNo"></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio-group v-model="deviceForm.status">
                    <el-radio :label="10">启用</el-radio>
                    <el-radio :label="20">停用</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="加密盐值" prop="salt">
                <el-input v-model="deviceForm.salt"></el-input>
            </el-form-item>
            <el-form-item label="设备跳转url" prop="dthUrl">
                <el-input v-model="deviceForm.dthUrl"></el-input>
            </el-form-item>
            <el-form-item label="支付url" prop="payUrl">
                <el-input v-model="deviceForm.payUrl"></el-input>
            </el-form-item>
            <el-form-item label="是否测试" prop="whetherTest">
                <el-radio-group v-model="deviceForm.whetherTest">
                    <el-radio :label="10">否</el-radio>
                    <el-radio :label="20">是</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="类型" prop="type">
                <el-radio-group v-model="deviceForm.type">
                    <el-radio :label="20">接口机</el-radio>
                    <el-radio :label="10">收银机</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="设备类型" prop="colMachType">
                <el-radio-group v-model="deviceForm.colMachType">
                    <el-radio v-if="deviceSource('10')&&deviceForm.type==10" :label="10">京东自助</el-radio>
                    <el-radio v-if="deviceSource('20')&&deviceForm.type==10" :label="20">微信大屏自助</el-radio>
                    <el-radio v-if="deviceSource('30')&&deviceForm.type==10" :label="30">小屏自助</el-radio>
                    <el-radio v-if="deviceSource('40')&&deviceForm.type==10" :label="40">扫枪</el-radio>
                    <el-radio v-if="deviceSource('50')&&deviceForm.type==20" :label="50">到家小程序</el-radio>
                    <el-radio v-if="deviceSource('60')&&deviceForm.type==10" :label="60">双屏自助</el-radio>
                    <el-radio v-if="deviceSource('70')&&deviceForm.type==10" :label="70">彩娱自助</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="devicePopup=false">取消</el-button>
            <el-button type="primary" @click="deviceSubmitForm('deviceForm')">保存</el-button>
          </span>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane name="integralrule" label="积分" v-if="btnPower.ShopIntegralrule">
        <div class="filter-container">
          <el-button v-if="btnPower.ShopIntegralruleAdd" class="filter-item" type="primary" icon="el-icon-document" @click="getIntegralrulePoput()">添加</el-button>
        </div>

        <el-table
          :data="integralruleLists"
          v-loading="integralruleListLoading"
          element-loading-text="请稍后"
          border
          fit
          highlight-current-row>
          <el-table-column
                  type="index"
                  label="序号"
                  width="100"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="type"
                  :formatter="integralruleType"
                  label="类型"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="item"
                  label="星期/日期"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="factor"
                  label="积分倍数"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="createAt"
                  :formatter="timeFormat"
                  label="创建时间"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="modAt"
                  :formatter="timeFormat"
                  label="修改时间"
                  align="center">
          </el-table-column>
          <el-table-column
              fixed="right"
              label="操作"
              width="150"
              align="center">
              <template slot-scope="scope">
                  <el-button v-if="btnPower.ShopIntegralruleRev" type="primary" size="mini" @click="getIntegralrulePoput(scope.row)">修改</el-button>
                  <el-button v-if="btnPower.ShopIntegralruleDel" type="danger" size="mini" @click="getDelIntegralrule(scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>
        <pagination v-show="integralruleTotal>0" :total="integralruleTotal" :page.sync="integralruleParams.current" :limit.sync="integralruleParams.size" @pagination="getIntegralruleList" />
        <el-dialog
            :title="integralrulePopupType==1?'添加积分规则':'修改积分规则'"
            :visible.sync="integralrulePopup"
            :close-on-click-modal=false
            :destroy-on-close=true
            width="500px"
            center>
            <el-form :model="integralruleForm" ref="integralruleForm" label-width="80px" class="demo-ruleForm">
              <el-form-item label="类型">
                  <el-select v-model="integralruleForm.type" style="width:40%;">
                      <el-option label="星期" :value="10" ></el-option>
                      <el-option label="日期" :value="20" ></el-option>
                      <el-option label="特价" :value="30" ></el-option>
                      <el-option label="会员特价" :value="50" ></el-option>
                  </el-select>
                  <el-select v-model="integralruleForm.item" style="width:40%;" v-if="integralruleForm.type==10||integralruleForm.type==20">
                      <el-option
                              v-for="item in integralruleItem"
                              :label="item.name"
                              :value="item.code"
                              :key="item.code"
                              >
                      </el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="">
                  <el-input-number :min="0" :precision="2" style="width:40%;" v-model="integralruleForm.factor"></el-input-number>倍积分
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="integralrulePopup=false">取消</el-button>
              <el-button type="primary" @click="getIntegralruleForm">保存</el-button>
            </span>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane name="bag" label="购物袋" v-if="btnPower.ShopBag">
        <div class="filter-container">
          <el-button v-if="btnPower.ShopBagAdd" class="filter-item" type="primary" icon="el-icon-document" @click="getBagPoput()">添加</el-button>
        </div>
        <el-table
          :data="bagLists"
          v-loading="bagListLoading"
          element-loading-text="请稍后"
          border
          fit
          highlight-current-row>
          <el-table-column
                  type="index"
                  label="序号"
                  width="100"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="goodsNo"
                  label="购物袋编号"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="type"
                  :formatter="bagType"
                  label="购物袋类型"
                  width="150"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="price"
                  label="购物袋价格"
                  width="150"
                  v-if="shopInfo.dockType != 10"
                  align="center">
          </el-table-column>
          <el-table-column
                  prop="createAt"
                  :formatter="timeFormat"
                  label="创建时间"
                  align="center">
          </el-table-column>
          <el-table-column
              fixed="right"
              label="操作"
              width="150"
              align="center">
              <template slot-scope="scope">
                  <el-button v-if="btnPower.ShopBagRev" type="primary" size="mini" @click="getBagPoput(scope.row)">修改</el-button>
                  <el-button v-if="btnPower.ShopBagDel" type="danger" size="mini" @click="getDelBag(scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>
        <pagination v-show="bagTotal>0" :total="bagTotal" :page.sync="bagParams.current" :limit.sync="bagParams.size" @pagination="getBagList" />
        <el-dialog
            :title="bagPopupType==1?'添加购物袋':'修改购物袋'"
            :visible.sync="bagPopup"
            :close-on-click-modal=false
            :destroy-on-close=true
            width="500px"
            center>
            <el-form :model="bagForm" ref="bagForm" :rules="bagRules" label-width="100px" class="demo-ruleForm">
              <el-form-item label="购物袋编号" prop="goodsNo" placeholder="请输入购物袋编号">
                  <el-input v-model="bagForm.goodsNo" style="width:60%;"></el-input>
              </el-form-item>
              <el-form-item label="所属类型" prop="type">
                  <el-select v-model="bagForm.type" style="width:60%;" filterable>
                      <el-option label="小袋" :value="10"></el-option>
                      <el-option label="中袋" :value="20"></el-option>
                      <el-option label="大袋" :value="30"></el-option>
                      <el-option label="超大袋" :value="40"></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="购物袋价格" prop="price" v-if="shopInfo.dockType != 10">
                  <el-input-number v-model="bagForm.price" style="width:60%;" :min="0.1" :max="10" :step="0.1" :precision="2"></el-input-number>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="bagPopup=false">取消</el-button>
              <el-button type="primary" @click="BagsubmitForm('bagForm')">保存</el-button>
            </span>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane name="prod" label="无码商品" v-if="btnPower.ShopProd">
        <div class="filter-container">
          <el-button v-if="btnPower.ShopProdAdd" class="filter-item" type="primary" icon="el-icon-document" @click="getProdPoput()">添加</el-button>
        </div>
        <el-table
          :data="prodLists"
          v-loading="prodListLoading"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row>
          <el-table-column
            type="index"
            label="序号"
            width="100"
            align="center">
          </el-table-column>
          <el-table-column
            prop="goodsNo"
            label="商品编码"
            align="center">
          </el-table-column>
          <el-table-column
            prop="name"
            label="商品名称"
            align="center">
          </el-table-column>
          <el-table-column
            prop="price"
            label="价格"
            width="150"
            v-if="shopInfo.dockType != 10"
            align="center">
          </el-table-column>
          <el-table-column
            prop="createAt"
            :formatter="timeFormat"
            label="创建时间"
            align="center">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="150"
            align="center">
            <template slot-scope="scope">
              <el-button v-if="btnPower.ShopProdRev" type="primary" size="mini" @click="getProdPoput(scope.row)">修改</el-button>
              <el-button v-if="btnPower.ShopProdDel" type="danger" size="mini" @click="getDelProd(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="prodTotal>0" :total="prodTotal" :page.sync="prodParams.current" :limit.sync="prodParams.size" @pagination="getProdList" />
        <el-dialog
          :title="prodPopupType==1?'添加商品':'修改商品'"
          :visible.sync="prodPopup"
          :close-on-click-modal=false
          :destroy-on-close=true
          width="500px"
          center>
          <el-form :model="prodForm" ref="prodForm" :rules="prodRules" label-width="100px" class="demo-ruleForm">
            <el-form-item label="商品名称" prop="name" placeholder="请输入商品名称">
              <el-input v-model="prodForm.name" style="width:60%;"></el-input>
            </el-form-item>
            <el-form-item label="商品编号" prop="goodsNo" placeholder="请输入商品编号">
              <el-input v-model="prodForm.goodsNo" style="width:60%;"></el-input>
            </el-form-item>
            <el-form-item label="商品价格" prop="price" v-if="shopInfo.dockType != 10">
              <el-input-number v-model="prodForm.price" style="width:60%;" :min="0.1" :step="0.1" :precision="2"></el-input-number>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
              <el-button @click="prodPopup=false">取消</el-button>
              <el-button type="primary" @click="ProdsubmitForm('prodForm')">保存</el-button>
            </span>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane name="ticket" label="小票" v-if="btnPower.ShopTicket">
        <el-form ref="ticketInfo" :model="ticketInfo" :rules="ticketRules" label-width="120px" style="float: left; width: 510px;">
          <el-form-item label="小票一级标题">
            <el-input type="textarea" :rows="3" v-model="ticketInfo.shopName" placeholder="请输入小票一级标题" size="small"></el-input>
          </el-form-item>
          <el-form-item label="小票二级标题" prop="subTitle">
              <el-input  v-model="ticketInfo.subTitle" placeholder="请输入小票二级标题"></el-input>
          </el-form-item>
          <el-form-item label="二维码描述" prop="adContent">
              <el-input  v-model="ticketInfo.adContent" placeholder="请输入二维码描述"></el-input>
          </el-form-item>
          <el-form-item label="二维码地址" prop="qrCodeLink">
              <el-input  v-model="ticketInfo.qrCodeLink" placeholder="请输入二维码地址" style="float:left;"></el-input>
              <el-upload
                class="upload-demo"
                :action="bannerDomain+'/ticket/qrcode'"
                :show-file-list="false"
                name="file"
                :headers="bannerHeader"
                :on-success="getCodeImage"
                :before-upload="beforeAvatarUpload"
                style="float:left; margin-left:10px;">
                <el-button size="small" type="primary">上传图片</el-button>
              </el-upload>
          </el-form-item>
          <el-form-item label="底部描述" prop="adBottom">
              <el-input type="textarea" :rows="3"  v-model="ticketInfo.adBottom" placeholder="请输入底部描述"></el-input>
          </el-form-item>
          <el-form-item>
              <el-button type="primary" @click="ticketsubmitForm('ticketInfo')">保存</el-button>
              <el-button @click="ticketResetForm('ticketInfo')">重置</el-button>
          </el-form-item>
        </el-form>
        <el-image :src="ticketImg" class="ticketImg" style="float: left; width: 250px; margin-left: 50px;"></el-image>
      </el-tab-pane>

      <el-tab-pane name="banner" label="广告" v-if="btnPower.ShopBanner">
        <div class="filter-container">
          <el-button v-if="btnPower.ShopBannerAdd" class="filter-item" type="primary" icon="el-icon-document" @click="getBannerButton()">添加</el-button>
        </div>
        <el-table
          :data="bannerLists"
          v-loading="bannerListLoading"
          element-loading-text="请稍后"
          border
          fit
          highlight-current-row>
          <el-table-column
            type="index"
            label="序号"
            width="80"
            align="center">
          </el-table-column>
          <el-table-column
            prop="title"
            label="轮播名称"
            width="150"
            align="center">
          </el-table-column>
          <el-table-column
            prop="imgUrl"
            label="图片"
            width="180"
            align="center">
            <template slot-scope="scope">
              <img :src="scope.row.imgUrl" style="width: 160px; height: 80px;"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="sortNum"
            label="排序顺序"
            width="80"
            align="center">
          </el-table-column>
          <el-table-column
            prop="status"
            :formatter="bannerStatus"
            label="状态"
            width="80"
            align="center">
          </el-table-column>
          <el-table-column
            prop="publishStartTime"
            :formatter="timeFormat"
            label="上架时间"
            width="160"
            align="center">
          </el-table-column>
          <el-table-column
            prop="publishEndTime"
            :formatter="timeFormat"
            label="下架时间"
            width="160"
            align="center">
          </el-table-column>
          <el-table-column
            prop="type"
            :formatter="bannerTypes"
            label="类型"
            width="150"
            align="center">
          </el-table-column>
          <el-table-column
            prop="source"
            :formatter="bannerSource"
            label="来源"
            width="150"
            align="center">
          </el-table-column>
          <el-table-column
            prop="createAt"
            :formatter="timeFormat"
            label="创建时间"
            width="160"
            align="center">
          </el-table-column>
          <el-table-column
            prop="modAt"
            :formatter="timeFormat"
            label="修改时间"
            width="160"
            align="center">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="160"
            align="center">
            <template slot-scope="scope">
              <el-button v-if="btnPower.ShopBannerRev" size="small" @click="getBannerButton(scope.row)">修改</el-button>
              <el-button v-if="btnPower.ShopBannerDel" type="danger" size="small" @click="getDelBanner(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-dialog
            :title="bannerPopupType==1?'添加广告':'修改广告'"
            :visible.sync="bannerPopup"
            :close-on-click-modal=false
            :destroy-on-close=true
            width="500px"
            center>
            <el-form :model="bannerForm" ref="bannerForm" :rules="bannerRules" label-width="100px" class="demo-ruleForm">
                <el-form-item label="广告图片" prop="imgUrl">
                  <el-upload
                    class="avatar-uploader"
                    :action="bannerDomain+'/upload/upload'"
                    :show-file-list="false"
                    :headers="bannerHeader"
                    :on-success="getAddImage"
                    :before-upload="beforeAvatarUpload">
                    <img v-if="bannerForm.imgUrl" :src="bannerForm.imgUrl" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </el-upload>
                </el-form-item>
                <el-form-item label="广告名称" prop="title">
                  <el-input v-model.number="bannerForm.title"></el-input>
                </el-form-item>
                <el-form-item label="排序顺序" prop="sortNum">
                  <el-input v-model.number="bannerForm.sortNum"></el-input>
                </el-form-item>
                <el-form-item label="上架时间" prop="publishStartTime">
                  <el-date-picker
                    v-model="bannerForm.publishStartTime"
                    value-format="timestamp"
                    type="datetime"
                    placeholder="选择上架日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="下架时间" prop="publishEndTime">
                  <el-date-picker
                    v-model="bannerForm.publishEndTime"
                    value-format="timestamp"
                    type="datetime"
                    placeholder="选择下架日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="状态" prop="status">
                  <el-radio-group v-model="bannerForm.status">
                    <el-radio :label="10">上架</el-radio>
                    <el-radio :label="20">下架</el-radio>
                  </el-radio-group>
                </el-form-item>
                <!-- <el-form-item label="类型" prop="type">
                  <el-radio-group v-model="bannerForm.type">
                    <el-radio :label="10">首屏广告</el-radio>
                    <el-radio :label="20">支付广告</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="来源" prop="source">
                  <el-radio-group v-model="bannerForm.source">
                    <el-radio :label="10">商户</el-radio>
                    <el-radio :label="20">中台</el-radio>
                  </el-radio-group>
                </el-form-item> -->
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="bannerPopup=false">取消</el-button>
              <el-button type="primary" @click="bannersubmitForm('bannerForm')">保存</el-button>
            </span>
        </el-dialog>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style>
.avatar-uploader .el-upload { border: 1px dashed #EEEEEE; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; }
.avatar-uploader .el-upload:hover { border-color: #409EFF; }
.avatar-uploader-icon { font-size: 28px; color: #8c939d; width: 120px; height: 180px; line-height: 180px; text-align: center; }
.avatar { width: 120px; height: 180px; display: block;}
</style>

<script>
import Pagination from '@/components/Pagination'
import imgTicket from '@/assets/images/ticket.png'
import { domain } from "@/utils/config.js"
import { getToken } from '@/utils/auth'
import { shopBase, shopAddAllBase, erpsysBaseAll, deviceList, addRevDevice, delDevice, ticketAll, addRevTicket,integralruleList, addDevIntegralrule, delIntegralrule, delBag ,addDevBag ,bagList, bannerList, addRevBanner, delBanner, loginResetPwd } from '@/api/api.verify.js'

export default {
  components:{Pagination},
  name: 'ShopSet',
  data() {
    return {
      btnPower:JSON.parse(localStorage.getItem('btnList')),//按钮权限
      listLoading: true,
      activeName:'edit',
      shopInfo:{},//店铺信息

      //编辑
      disabled:false,
      markets: [],
      erps: [],
      salesList: [],
      agentList: [],
      payBtnTemplateList:[],//支付按钮模板列表
      editRules:{
        sources:[
          {required: true, message: '请选择商户类型', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '请输入店铺名称', trigger: 'blur'}
          ,{min: 3, max: 35, message: '长度在 3 到 35 个字符', trigger: 'blur'}
        ],
        erpSysId: [
          {required: true, message: '请选择ERP系统', trigger: 'change'}
        ],
        marketId: [
          {required: true, message: '请选择商超', trigger: 'change'}
        ],
        salesId: [
          {required: true, message: '请选择销售人员', trigger: 'change'}
        ],
        agentId: [
          {required: true, message: '请选择代理商', trigger: 'change'}
        ],
        payBtnTemplateId: [
          {required: true, message: '请选择支付按钮模板', trigger: 'change'}
        ],
        shopNo: [
          {required: false, message: '请输入商户编号', trigger: 'blur'}
        ],
        deviceList: [
          {required: true, message: '请输入设备SN', trigger: 'blur'}
        ],
        linkmanPhone: [
          {required: false, message: '请输入登录账号', trigger: 'blur'},
          {min: 3, max: 35, message: '长度在 3 到 35 个字符', trigger: 'blur'}
        ],
      },//表单验证
      editForm:{
      },//编辑表单

      //设备
      deviceListLoading:true,
      deviceLists:[],//设备列表
      deviceTotal:0,//设备列表总条数
      deviceParams:{
        current: 1,
        size: 10,
      },//设备列表查询条件
      devicePopupType:1,//1 添加  2 编辑
      devicePopup:false,//设备弹窗状态
      deviceForm:{
        id: null,
        name: '',
        salt:'',
        deviceNo: '',
        status: 10,
        whetherTest: 10,
        dthUrl: 'cymp.caiyu123.com',
        payUrl:'cypay.caiyu123.com',
        type: 10,
        colMachType: 10,
      },//设备表单
      deviceRules:{

      },//设备表单验证
      //积分
      integralruleListLoading:true,
      integralruleLists:[],//积分列表
      integralruleTotal:0,//积分列表总条数
      integralruleParams:{
        current: 1,
        size: 10,
      },//积分列表查询条件
      integralrulePopupType:1,//1 添加  2 编辑
      integralrulePopup:false,//积分弹窗状态
      integralruleForm:{
        item: null,
        type: 10,
        factor:1,
      },//积分表单
      integralruleItem:[],//积分表单二级下拉
      integralruleWeekItems:[
        {"name":"星期一","code":"week1"},
        {"name":"星期二","code":"week2"},
        {"name":"星期三","code":"week3"},
        {"name":"星期四","code":"week4"},
        {"name":"星期五","code":"week5"},
        {"name":"星期六","code":"week6"},
        {"name":"星期日","code":"week7"},
      ],//积分表单一级下拉星期
      integralruleDateItems:[],//积分表单一级下拉日期

      //购物袋
      bagListLoading:true,
      bagLists:[],//购物袋列表
      bagTotal:0,//购物袋列表总条数
      bagParams:{
        current: 1,
        size: 10,
      },//购物袋列表查询条件
      bagPopupType:1,//1 添加  2 编辑
      bagPopup:false,//购物袋弹窗状态
      bagForm:{
        goodsNo: null,
        prodType: 10,
        type: "10",
        price: '0.2',
      },//购物袋表单
      bagRules:{
        goodsNo: [
          {required: true, message: '请输入购物袋编号', trigger: 'blur'},
        ],
      },

      prodListLoading:true,
      prodLists:[],//无码商品列表
      prodTotal:0,//购物袋列表总条数
      prodParams:{
        current: 1,
        size: 10,
      },//购物袋列表查询条件
      prodPopupType:1,//1 添加  2 编辑
      prodPopup:false,//购物袋弹窗状态
      prodForm:{
        goodsNo: null,
        name:null,
        prodType: 20,
        type: "10",
        price: '0.2',
      },//购物袋表单
      prodRules:{
        goodsNo: [
          {required: true, message: '请输入商品编码', trigger: 'blur'},
          { pattern: /^[0-9]*$/, message: '请输入正确商品编码' }
        ],
      },
      //小票
      ticketInfo:{
        shopName:null,//小票一级标题
        subTitle:null,//小票二级标题
        adContent:null,//二维码描述
        qrCodeLink:null,//二维码地址
        adBottom:null,//底部描述
      },//小票信息
      ticketRules: {
          subTitle: [
              {required: false, message: '请输入小票标题', trigger: 'blur'},
              {min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur'}
          ],
          adBottom: [
              {required: true, message: '请输入小票底部描述', trigger: 'blur'},
              {min: 2, max: 150, message: '长度在 2 到 150 个字符', trigger: 'blur'}
          ],
      },//小票表单验证
      ticketImg:imgTicket,//小票图片
      //广告
      bannerListLoading:true,
      bannerHeader:{token:getToken()},
      bannerDomain:domain,
      bannerLists:[],//广告列表
      bannerTotal:0,//广告列表总条数
      bannerParams:{
        current: 1,
        size: 10,
      },//广告列表查询条件
      bannerPopupType:1,//1 添加  2 编辑
      bannerPopup:false,//广告弹窗状态
      bannerForm:{
        id: null,//轮播ID
        imgUrl:null,//轮播url
        title:null,//轮播名称
        sortNum:9,//轮播排序号
        publishStartTime:null,//上架时间
        publishEndTime:null,//下架时间
        status:10,//轮播上下架  10上架  20下架
        type:10,//10:首屏广告，20:支付广告
        source:10,//10:商户，20:中台
      },//广告表单
      bannerRules:{
        imgUrl: [
          {required: true, message: '请上传轮播图片', trigger: 'blur'},
        ],
        title: [
          {required: true, message: '请输入轮播名称', trigger: 'blur'},
        ],
        sortNum: [
          {required: true, message: '请输入排序顺序', trigger: 'blur'},
          { type: 'number', message: '请输入正确排序顺序'},
        ],
        status: [
          {required: true, message: '请选择状态', trigger: 'blur'},
        ],
      },//广告表单验证

    }
  },
  created() {
    this.shopInfo=this.$route.query
    this.getErps();
    this.getStart()
  },
  methods: {
    getStart(){//初始化
      for(var i = 1;i<=31;i++){
        var name = i + "号";
        var code = "date" + i;
        var item = {"name":name,"code":code};
        this.integralruleDateItems.push(item);
      }
      this.getShopForm()
      if(this.shopInfo.name){
        let data={}
        data.name=this.shopInfo.name
        this.handleClick(data)
        this.activeName=this.shopInfo.name
      }
    },

    //编辑
    getShopForm() {//获取店铺信息表单
        let _this = this;
        let data={}
        data.id=this.shopInfo.shopId
        shopBase(data).then(d=>{
          let editForm=d.data
          editForm.sources=editForm.source.split(",")
          _this.editForm = editForm
          _this.shopInfo.dockType=d.data.dockType
        });
    },
    editSubmitForm(formName) {//编辑表单验证
      let _this = this;
      this.$refs[formName].validate((valid) => {
        if(valid){
          _this.getEditForm()
        }
      });
    },
    getEditForm(){//提交表单
      let _this=this
      let editForm=JSON.parse(JSON.stringify(_this.editForm));
      shopAddAllBase(editForm,'PUT').then(d=>{
          _this.$message({
            message: "修改成功",
            type: 'success',
            duration: 2000
          });
          _this.getShopForm()
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();//重置表单
    },
    getMarkets() {
      let _this = this;
      let data={};
      data.status=10;
      marketAll(data).then(d=>{
        _this.markets = d.data;
      });
    },
    getErps() {
      let _this = this;
      let data={};
      data.status=10;
      erpsysBaseAll(data).then(d=>{
        _this.erps = d.data;
      });
    },
    getSalesList() {
      let _this = this;
      let data={};
      data.status=10;
      salesAll(data).then(d=>{
        _this.salesList = d.data;
      });
    },
    getPayBtnTemplateList(){//获取支付按钮模板列表
      let _this=this;
      let data={};
      cytemplateListAll(data).then(d=>{
        _this.payBtnTemplateList=d.data;
      });
    },
    getLoginResetPwd(){//重置密码
      let e=this.shopInfo
      let _this=this;
      this.$confirm('是否重置'+e.shopName+'店密码','提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
          let data={}
          data.id=e.shopId
          loginResetPwd(data).then(d=>{
            _this.$message({
                type: 'success',
                message: '重置成功!'
            });
          });
      }).catch(() => {
          this.$message({
          type: 'info',
          message: '已取消重置'
          });
      });
    },
    isHid() {
        return this.editForm.inspect == 10?true:false;
    },

    //设备
    getDeviceList(){//获取设备列表
      let _this=this
      let data=this.deviceParams
      data.shopId=this.shopInfo.shopId
      this.deviceListLoading=true
      deviceList(data).then(d=>{
        _this.deviceLists=d.data.records
        _this.deviceTotal=Number(d.data.total)
      }).finally(d=>{
        _this.deviceListLoading=false
      })
    },
    getDevicePoput(e){
      if(e){//修改
        this.devicePopupType=2
        this.deviceForm.id=e.id
        this.deviceForm.name=e.name
        this.deviceForm.salt=e.salt
        this.deviceForm.deviceNo=e.deviceNo
        this.deviceForm.status=e.status
        this.deviceForm.whetherTest=e.whetherTest
        this.deviceForm.dthUrl=e.dthUrl
        this.deviceForm.payUrl=e.payUrl
        this.deviceForm.type=e.type
        this.deviceForm.colMachType=e.colMachType
      }else{//添加
        this.devicePopupType=1
        this.deviceForm.id=null
        this.deviceForm.name= ''
        this.deviceForm.salt=''
        this.deviceForm.deviceNo= ''
        this.deviceForm.status= 10
        this.deviceForm.whetherTest= 10
        this.deviceForm.dthUrl= 'cymp.caiyu123.com'
        this.deviceForm.payUrl='cypay.caiyu123.com'
        this.deviceForm.type= 10
        this.deviceForm.colMachType= 10
      }
      this.devicePopup=true
    },
    deviceSubmitForm(formName){//设备表单验证
      let _this = this;
      this.$refs[formName].validate((valid,object) => {
          if(valid) {
              _this.getDeviceForm()
          }
      });
    },
    getDeviceForm(){//设备提交保存
      if(this.devicePopupType==1){//添加
        var method="POST"
        var alert="添加"
      }else if(this.devicePopupType==2){//修改
        var method="PUT"
        var alert="修改"
      }
      let _this=this
      let data=this.deviceForm
      data.shopId=this.shopInfo.shopId
      addRevDevice(data,method).then(d=>{
        _this.$message({
          message: alert+'成功',
          type: 'success'
        });
        this.getDeviceList();
      }).finally(d=>{
        _this.devicePopup=false
      })
    },
    getDelDevice(e){//删除设备
      let _this=this;
      this.$confirm('是否删除次设备','提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let data={}
        data.id=e.id;
        delDevice(data).then(d=>{
          _this.$message({
            type: 'success',
            message: '删除成功!'
          });
          _this.getDeviceList()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    deviceSource(e) {
      if(this.editForm.source){
        return this.editForm.source.indexOf(e)!=-1
      }else{
        return false
      }
    },

    //积分
    getIntegralruleList(){//获取积分列表
      let _this=this
      let data=this.integralruleParams
      data.shopId=this.shopInfo.shopId
      this.integralruleListLoading=true
      integralruleList(data).then(d=>{
        _this.integralruleLists=d.data.records
        _this.integralruleTotal=Number(d.data.total)
      }).finally(d=>{
        _this.integralruleListLoading=false
      })
    },
    getIntegralrulePoput(e){//点击积分列表  添加/修改
      if(e){//修改
        this.integralrulePopupType=2
        this.integralruleForm.item=e.item
        this.integralruleForm.type=e.type
        this.integralruleForm.factor=e.factor
        this.integralruleForm.id=e.id
      }else{//添加
        this.integralrulePopupType=1
        this.integralruleForm.item='week1'
        this.integralruleForm.type=10
        this.integralruleForm.factor=1
        this.integralruleForm.id=null
      }
      this.integralrulePopup=true
    },
    getIntegralruleForm(){//积分添加修改
      if(this.integralrulePopupType==1){//添加
        var method="POST"
        var alert="添加"
      }else if(this.integralrulePopupType==2){//修改
        var method="PUT"
        var alert="修改"
      }
      let _this=this
      let data=this.integralruleForm
      data.shopId=this.shopInfo.shopId
      addDevIntegralrule(data,method).then(d=>{
        _this.getIntegralruleList();
        _this.$message({
          message: alert+'成功',
          type: 'success'
        });
      }).finally(d=>{
        _this.integralrulePopup=false
      })
    },
    getDelIntegralrule(e){//积分规则删除
        let _this=this;
        this.$confirm('是否删除此积分规则?','提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          let data={}
          data.id=e.id;
          delIntegralrule(data).then(d=>{
            _this.$message({
                type: 'success',
                message: '删除成功!'
            });
            _this.getIntegralruleList();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    //购物袋
    getBagList(){//获取购物袋列表
      let _this=this
      let data=this.bagParams
      data.shopId=this.shopInfo.shopId
      data.prodType=10;
      this.bagListLoading=true
      bagList(data).then(d=>{
        _this.bagLists=d.data.records
        _this.bagTotal=Number(d.data.total)
      }).finally(d=>{
        _this.bagListLoading=false
      })
    },
    getBagPoput(e){//点击购物袋列表  添加/修改
      if(e){//修改
        this.bagPopupType=2
        this.bagForm.id=e.id
        this.bagForm.goodsNo=e.goodsNo
        this.bagForm.type=e.type
        this.bagForm.price=e.price
      }else{//添加
        this.bagForm.id=null
        this.bagPopupType=1
        this.bagForm.goodsNo=null
        this.bagForm.type="10"
        this.bagForm.prodType="10"
        this.bagForm.price='0.2'
      }
      this.bagPopup=true
    },
    BagsubmitForm(formName){//购物袋表单验证
      let _this = this;
      this.$refs[formName].validate((valid,object) => {
          if(valid) {
              _this.getBagForm()
          }
      });
    },
    getBagForm(){//购物袋提交保存
      if(this.bagPopupType==1){//添加
        var method="POST"
        var alert="添加"
      }else if(this.bagPopupType==2){//修改
        var method="PUT"
        var alert="修改"
      }
      let _this=this
      let data=this.bagForm
      data.shopId=this.shopInfo.shopId
      addDevBag(data,method).then(d=>{
        _this.$message({
          message: alert+'成功',
          type: 'success'
        });
        this.getBagList();
      }).finally(d=>{
        _this.bagPopup=false
      })
    },
    getDelBag(e){//删除购物袋
        let _this=this;
        this.$confirm('是否删除此购物袋?','提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          let data={}
          data.id=e.id;
          delBag(data).then(d=>{
            _this.$message({
                type: 'success',
                message: '删除成功!'
            });
            _this.getBagList();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    //无码商品
    getProdList(){//获取无码商品列表
      let _this=this
      let data=this.bagParams
      data.shopId=this.shopInfo.shopId
      data.prodType=20;
      this.prodListLoading=true
      bagList(data).then(d=>{
        _this.prodLists=d.data.records
        _this.prodTotal=Number(d.data.total)
      }).finally(d=>{
        _this.prodListLoading=false
      })
    },
    getProdPoput(e){//点击购物袋列表  添加/修改
      if(e){//修改
        this.prodPopupType=2
        this.prodForm.id=e.id
        this.prodForm.goodsNo=e.goodsNo
        this.prodForm.name=e.name
        this.prodForm.type=e.type
        this.prodForm.price=e.price
      }else{//添加
        this.prodForm.id=null
        this.prodPopupType=1
        this.prodForm.goodsNo=null
        this.prodForm.name=null
        this.prodForm.type="10"
        this.prodForm.prodType="20"
        this.prodForm.price='0.2'
      }
      this.prodPopup=true
    },
    ProdsubmitForm(formName){//无码商品表单验证
      let _this = this;
      this.$refs[formName].validate((valid,object) => {
          if(valid) {
              _this.getProdForm()
          }
      });
    },
    getProdForm(){//无码商品提交保存
      if(this.prodPopupType==1){//添加
        var method="POST"
        var alert="添加"
      }else if(this.prodPopupType==2){//修改
        var method="PUT"
        var alert="修改"
      }
      let _this=this
      let data=this.prodForm
      data.shopId=this.shopInfo.shopId
      addDevBag(data,method).then(d=>{
        _this.$message({
          message: alert+'成功',
          type: 'success'
        });
        this.getProdList();
      }).finally(d=>{
        _this.prodPopup=false
      })
    },
    getDelProd(e){//删除无码商品
        let _this=this;
        this.$confirm('是否删除此商品?','提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          let data={}
          data.id=e.id;
          delBag(data).then(d=>{
            _this.$message({
                type: 'success',
                message: '删除成功!'
            });
            _this.getBagList();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    //小票
    getTicketInfo(){//获取小票信息
      let _this=this
      let data={}
      data.shopId=this.shopInfo.shopId
      ticketAll(data).then(d=>{
        if(d.data){
          _this.ticketInfo=d.data
        }
      })
    },
    ticketsubmitForm(formName){//小票表单验证
      let _this = this;
      this.$refs[formName].validate((valid,object) => {
          if(valid) {
              _this.getTicketForm()
          }
      });
    },
    getTicketForm(){//提交小票表单
      let _this=this
      let data=this.ticketInfo
      data.shopId=this.shopInfo.shopId
      addRevTicket(data).then(d=>{
        _this.$message({
          type: 'success',
          message: '设置成功!'
        });
        _this.getTicketInfo()
      })
    },
    ticketResetForm(formName){//小票表单重置
      this.$refs[formName].resetFields();
    },
    getCodeImage(d) {//上传图片成功返回
      if(d.code==1){
        this.ticketInfo.qrCodeLink=d.data
      }else{
        this.$message.error(d.msg);
      }
    },


    //广告
    getBannerList(){//获取广告列表
      let _this=this
      let data={}
      data.shopId=this.shopInfo.shopId
      this.bannerListLoading=true
      bannerList(data).then(d=>{
        _this.bannerLists=d.data.records
      }).finally(d=>{
        _this.bannerListLoading=false
      })
    },
    getBannerButton(e){//点击广告列表  添加/修改
      if(e){//修改
        this.bannerPopupType=2
        this.bannerForm.id=e.id
        this.bannerForm.imgUrl=e.imgUrl
        this.bannerForm.title=e.title
        this.bannerForm.sortNum=e.sortNum
        this.bannerForm.publishStartTime=e.publishStartTime+'000'
        this.bannerForm.publishEndTime=e.publishEndTime+'000'
        this.bannerForm.status=e.status
        this.bannerForm.type=e.type
        this.bannerForm.source=e.source
      }else{//添加
        this.bannerForm.id=null
        this.bannerPopupType=1
        this.bannerForm.imgUrl=null
        this.bannerForm.title=null
        this.bannerForm.sortNum=9
        this.bannerForm.publishStartTime=null
        this.bannerForm.publishEndTime=null
        this.bannerForm.status=10
        this.bannerForm.type=10
        this.bannerForm.source=10
      }
      this.bannerPopup=true
    },
    bannersubmitForm(formName){//广告表单验证
      let _this = this;
      this.$refs[formName].validate((valid,object) => {
          if(valid) {
              _this.getBannerForm()
          }
      });
    },
    getBannerForm(){//广告提交保存
      if(this.bannerPopupType==1){//添加
        var method="POST"
        var alert="添加"
      }else if(this.bannerPopupType==2){//修改
        var method="PUT"
        var alert="修改"
      }
      let _this=this
      let data=this.bannerForm
      data.shopId=this.shopInfo.shopId
      data.publishStartTime=data.publishStartTime/1000;
      data.publishEndTime=data.publishEndTime/1000;
      addRevBanner(data,method).then(d=>{
        _this.$message({
          message: alert+'成功',
          type: 'success'
        });
        this.getBannerList();
      }).finally(d=>{
        _this.bannerPopup=false
      })
    },
    getDelBanner(e){//删除广告
      let _this=this;
      this.$confirm('是否删除此广告?','提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let data={}
        data.id=e.id;
        delBanner(data,"DELETE").then(d=>{
          _this.$message({
              type: 'success',
              message: '删除成功!'
          });
          _this.getBannerList();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getAddImage(res) {//上传图片成功返回
      if(res.code==1){
        this.bannerForm.imgUrl = res.data.imageUrl;
      }else{
        this.$message.error(res.msg);
      }
    },
    beforeAvatarUpload(file) {//上传图片验证
      const isJPG = file.type === 'image/jpeg'||file.type ==='image/png';
      const isLt1M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        this.$message.error('上传图片只能是 JPG/PNG 格式!');
      }
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 2MB!');
      };
    },

    handleClick(tab){//点击tabs触发
        switch(tab.name){
          case "edit"://编辑
            this.getShopForm()
            break;
          case "device"://设备
            this.getDeviceList()
            break;
          case "integralrule"://积分
            this.getIntegralruleList()
            break;
          case "bag"://购物袋
            this.getBagList()
            break;
          case "prod"://无码商品
            this.getProdList()
            break;
          case "ticket"://小票
            this.getTicketInfo()
            break;
          case "banner"://广告
            this.getBannerList()
            break;
          default:
            this.getShopForm()
        }
    },

    timeFormat(row, column, cellValue, index) {//时间戳转换日期
      return this.common.getLocalTime(parseInt(cellValue) * 1000);
    },
    deviceStatus(row, column, cellValue, index) {//设备状态
      return cellValue == "10" ? "启用" : "停用";
    },
    deviceWhetherTest(row, column, cellValue, index) {//设备是否测试
      return cellValue == "10" ? "否" : "是";
    },
    integralruleType(row, column, cellValue, index){//积分类型
      var tip = "会员日";
      if(cellValue == 10){
          tip = "星期";
      }else if(cellValue == 20){
          tip = "日期";
      }else if(cellValue == 30){
          tip = "特价";
      }else if(cellValue == 50){
          tip = "会员特价";
      }
      return tip;
    },
    bagType(row, column, cellValue, index) {//购物袋类型
      var tip = "超大袋";
      if(cellValue == 10){
          tip = "小袋";
      }else if(cellValue == 20){
          tip = "中袋";
      }else if(cellValue == 30){
          tip = "大袋";
      }
      return tip;
    },
    bannerStatus(row, column, cellValue, index){//广告返回状态
      if(cellValue==10){
        return '上架';
      }else{
        return '下架';
      }
    },
    bannerTypes(row, column, cellValue, index){//广告返回状态
      if(cellValue==10){
        return '首屏广告';
      }else{
        return '支付广告';
      }
    },
    bannerSource(row, column, cellValue, index){//广告返回状态
      if(cellValue==10){
        return '商户';
      }else{
        return '中台';
      }
    },
    recommendType(row, column, cellValue){//是否推荐
      switch(Number(cellValue)){
        case 10:
          return '否';
        case 20:
          return '是';
        default:
          return '其他';
      }
    },
  },
  watch:{
    'integralruleForm.type':function(val){
      switch(Number(val)){
        case 10:
          this.integralruleItem=this.integralruleWeekItems
          this.integralruleForm.item="week1"
          break;
        case 20:
          this.integralruleItem=this.integralruleDateItems
          this.integralruleForm.item="date1"
          break;
        case 30:
          this.integralruleItem=[]
          this.integralruleForm.item = "disprice"
          break;
        case 50:
          this.integralruleItem=[]
          this.integralruleForm.item = "dvipprice"
          break;
        default:
          this.integralruleItem=[]
      }
    },
    "editForm.sources": function (e) {
      this.editForm.source=e.join(",")
    },
  }
}
</script>
